package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;
import com.stark.appwidget.lib.AppWidgetAdder;

import flc.ast.R;
import flc.ast.activity.CalendarWidgetActivity;
import flc.ast.activity.EditCalendarActivity;
import flc.ast.activity.EditTimeActivity;
import flc.ast.activity.EditWeatherActivity;
import flc.ast.activity.TimeWidgetActivity;
import flc.ast.activity.WeatherWidgetActivity;
import flc.ast.databinding.FragmentWidgetBinding;
import flc.ast.widget.calendar.Calendar10Widget;
import flc.ast.widget.calendar.Calendar1Widget;
import flc.ast.widget.calendar.Calendar2Widget;
import flc.ast.widget.calendar.Calendar3Widget;
import flc.ast.widget.calendar.Calendar4Widget;
import flc.ast.widget.calendar.Calendar5Widget;
import flc.ast.widget.calendar.Calendar6Widget;
import flc.ast.widget.calendar.Calendar7Widget;
import flc.ast.widget.calendar.Calendar8Widget;
import flc.ast.widget.calendar.Calendar9Widget;
import flc.ast.widget.time.Time10Widget;
import flc.ast.widget.time.Time1Widget;
import flc.ast.widget.time.Time2Widget;
import flc.ast.widget.time.Time3Widget;
import flc.ast.widget.time.Time4Widget;
import flc.ast.widget.time.Time5Widget;
import flc.ast.widget.time.Time6Widget;
import flc.ast.widget.time.Time7Widget;
import flc.ast.widget.time.Time8Widget;
import flc.ast.widget.time.Time9Widget;
import flc.ast.widget.weather.Weather1Widget;
import flc.ast.widget.weather.Weather2Widget;
import flc.ast.widget.weather.Weather3Widget;
import flc.ast.widget.weather.Weather4Widget;
import flc.ast.widget.weather.Weather5Widget;
import flc.ast.widget.weather.Weather6Widget;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link WidgetFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class WidgetFragment extends BaseNoModelFragment<FragmentWidgetBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_widget;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.llWeatherWidget.setOnClickListener(this);
        mDataBinding.llTimeWidget.setOnClickListener(this);
        mDataBinding.llCalendarWidget.setOnClickListener(this);
        mDataBinding.ivPhoto1.setOnClickListener(this);
        mDataBinding.ivPhoto2.setOnClickListener(this);
        mDataBinding.ivPhoto3.setOnClickListener(this);
        mDataBinding.ivPhoto4.setOnClickListener(this);
        mDataBinding.ivPhoto5.setOnClickListener(this);
        mDataBinding.ivPhoto6.setOnClickListener(this);
        mDataBinding.ivPhoto7.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.llWeatherWidget://天气组件
                startActivity(WeatherWidgetActivity.class);
                break;
            case R.id.llTimeWidget://时间组件
                startActivity(TimeWidgetActivity.class);
                break;
            case R.id.llCalendarWidget://时间组件
                startActivity(CalendarWidgetActivity.class);
                break;
            case R.id.ivPhoto1:
                EditCalendarActivity.start(mContext,8);
                break;
            case R.id.ivPhoto2:
                EditTimeActivity.start(mContext, 9, null);
                break;
//            case R.id.ivPhoto3:
//                EditCountdownActivity.start(mContext, 9, null);
//                break;
            case R.id.ivPhoto4:
                EditTimeActivity.start(mContext, 10, null);
                break;
            case R.id.ivPhoto5:
                EditCalendarActivity.start(mContext,9);
                break;
            case R.id.ivPhoto6:
                EditWeatherActivity.start(mContext,6);
                break;
            case R.id.ivPhoto7:
                EditCalendarActivity.start(mContext,10);
                break;
        }
    }

    @Override
    protected void initData() {
        AppWidgetAdder.getInstance().init();//初始化小组件
        AppWidgetAdder.getInstance().setCreateAppWidgetViewListener((layoutId, appWidgetId) -> {
            ToastUtils.showShort(R.string.create_suc);
            switch (layoutId) {
                case R.layout.widget_time2:
                    return new Time2Widget(appWidgetId);
                case R.layout.widget_time3:
                    return new Time3Widget(appWidgetId);
                case R.layout.widget_time4:
                    return new Time4Widget(appWidgetId);
                case R.layout.widget_time5:
                    return new Time5Widget(appWidgetId);
                case R.layout.widget_time6:
                    return new Time6Widget(appWidgetId);
                case R.layout.widget_time7:
                    return new Time7Widget(appWidgetId);
                case R.layout.widget_time8:
                    return new Time8Widget(appWidgetId);
                case R.layout.widget_time9:
                    return new Time9Widget(appWidgetId);
                case R.layout.widget_time10:
                    return new Time10Widget(appWidgetId);
                case R.layout.widget_calendar1:
                    return new Calendar1Widget(appWidgetId);
                case R.layout.widget_calendar2:
                    return new Calendar2Widget(appWidgetId);
                case R.layout.widget_calendar3:
                    return new Calendar3Widget(appWidgetId);
                case R.layout.widget_calendar4:
                    return new Calendar4Widget(appWidgetId);
                case R.layout.widget_calendar5:
                    return new Calendar5Widget(appWidgetId);
                case R.layout.widget_calendar6:
                    return new Calendar6Widget(appWidgetId);
                case R.layout.widget_calendar7:
                    return new Calendar7Widget(appWidgetId);
                case R.layout.widget_calendar8:
                    return new Calendar8Widget(appWidgetId);
                case R.layout.widget_calendar9:
                    return new Calendar9Widget(appWidgetId);
                case R.layout.widget_calendar10:
                    return new Calendar10Widget(appWidgetId);
                case R.layout.widget_weather1:
                    return new Weather1Widget(appWidgetId);
                case R.layout.widget_weather2:
                    return new Weather2Widget(appWidgetId);
                case R.layout.widget_weather3:
                    return new Weather3Widget(appWidgetId);
                case R.layout.widget_weather4:
                    return new Weather4Widget(appWidgetId);
                case R.layout.widget_weather5:
                    return new Weather5Widget(appWidgetId);
                case R.layout.widget_weather6:
                    return new Weather6Widget(appWidgetId);
                default:
                    return new Time1Widget(appWidgetId);
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        AppWidgetAdder.getInstance().deInit();
    }

}